//获取cookie、
var cookieJs = {
  flag: '_nyzy',
  getCookie(name) {
    if (name != 'token') {
      name = name + this.flag;
    }
    var arr,
      reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)');
    if ((arr = document.cookie.match(reg))) return arr[2];
    else return null;
  },
  setCookie(c_name, value, expiredays) {
    var exdate = new Date();
    if (c_name != 'token') {
      c_name = c_name + this.flag;
    }
    exdate.setDate(exdate.getDate() + expiredays);
    document.cookie = c_name + '=' + value + (expiredays == null ? '' : ';expires=' + exdate.toGMTString());
  },
  delCookie(name) {
    var exp = new Date();
    exp.setTime(exp.getTime() - 1);
    var cval = this.getCookie(name);
    if (cval != null) {
      if (name != 'token') {
        name = name + this.flag;
      }
      document.cookie = name + '=' + cval + ';expires=' + exp.toGMTString();
    }
  },
};

export default cookieJs;
